home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 3 / Cream of the Crop 3.iso / comm / prtcs155.zip / RFSFILEL.REX < prev    next >
OS/2 REXX Batch file  |  1994-01-14  |  9KB  |  252 lines

  1. /**/
  2. v="$VER: RFSFileList  Rexx FileList Creator Williamson 54.05"
  3. debug=0
  4. system="Amiga ECS"              /* Your system name and address here */
  5. listnote="Available files, updated "date()
  6. default="  Sorry, there is no description for this area"||cr||cr
  7. /*          ^^ spaces required! */
  8. /*  You must create these files */
  9. bbslist="BBS:TEXT/bbsn.list"    /* filearea config  */
  10. htext="CFG:filelistheader.txt"  /* System header */
  11. areatext='area.text'            /* area description */
  12. /* output files - edit names to suit */
  13. allfileslist="MAIL:FILELISTS/01670104.LST"    /* Output File List */
  14. allfilesarc ="MAIL:FILELISTS/01670104.LHA"    /* Archived Normal List */
  15. filesbbs ="files.bbs"           /* area desc and files */
  16. /* WB2 List Lformat parameters  */
  17. EXCLUDE='~(area.text|files.bbs|LZTEMP.#?|.info)'    /* LIST exclusion parameters    */
  18. LFMT_LIST='"%-20N%7L %-9D %C"'  /* all files list   */
  19. LFMT_BBS='"%-30N %C"'           /* areas.bbs        */
  20. FLLEN=77                        /* list line length  */
  21. MARGINALL=39                    /* margin for LFMT_LIST  - wraptofile prepends a space  */
  22. /* used internally */
  23. fileslist="OS4:TMP/ALST-"Pragma('ID')      /* temporary all file */
  24. tmpbbs="T:MLST-"Pragma('ID')            /* temporary area list */
  25. script="RFSfileList";ver="v"||right(v,5);fmvers=script ver
  26. cr='0a'x;lf='0a'x
  27. CSI='9b'x;AOFF=CSI||'0m';BOLD=CSI||'1m';ULINE=CSI||'4m';ITALICS=CSI||'3;40m'
  28.  
  29. if ~show("L", "rexxsupport.library") then
  30.     if ~addlib("rexxsupport.library", 0, -30, 0) then do
  31.             say "Couldn't access support.library !"
  32.             exit 20
  33.     end
  34.  
  35. options results
  36. options failat 20
  37. signal on halt
  38. signal on ioerr
  39. signal on break_c
  40. signal on break_d
  41.  
  42.     call close('STDOUT')
  43.     call open('STDOUT',"CON:0/10/640/100/"script ver"/CLOSE",'w')
  44.     call close('STDIN')
  45.     call open('STDIN','*','R')
  46.  
  47.     /* Start Area Processing */
  48.     if ~open('dlst',bbslist, 'R') then do
  49.         call writeln(STDOUT, "Couldn't open fileareas list" bbslist)
  50.         signal cleanup
  51.     end
  52.     if show('p',"ROOFLOG") then address 'ROOFLOG' 'logline' left(time(),5) script': Updating FILE Listing'
  53.     call writeln(STDOUT, lf||ITALICS||" "fmvers||lf||" by Robert Williamson 1:167/104.0@fidonet"||AOFF)
  54.     /* Start Area Processing */
  55.     call writeln(STDOUT, 'Reading file area configuration')
  56.     area=1
  57.     do while ~eof('dlst')
  58.         call writech(STDOUT,'.')
  59.         blstln=readln('dlst')
  60.         if blstln="" then iterate
  61.         parse var blstln Number.area '"' Path.area '"' '"' Name.area '"'
  62.         area=area+1
  63.     end /*eof*/
  64.     call close('dlst')
  65.  
  66.     areas=area-1
  67.     call writeln(STDOUT,'Found 'areas' file areas')
  68.  
  69.     /* open all file listing, put title, date and system header */
  70.     call writeln(STDOUT,ULINE||"Generating All Files Listing for "system||AOFF||cr)
  71.     if debug then call writeln(STDOUT,'Adding date/version header to 'fileslist)
  72.     open('tbl', fileslist, 'W')
  73.       call writech('tbl'," "fmvers" by Robert Williamson 1:167/104.0@fidonet"||cr)
  74.       call writech('tbl'," FileListing for" system  delstr(space(date(), 1, "-"), 8, 2) time()||cr ||cr)
  75.     close('tbl')
  76.  
  77.     if ~exists('htext') then do
  78.         if debug then call writeln(STDOUT,'Adding headerfile' htext 'to 'fileslist)
  79.         com='Type >> "'fileslist'" "'htext'"'
  80.         address COMMAND com
  81.     end
  82.  
  83.     do area=1 to areas
  84.         if area ~= 0 then do
  85.             areadir=addslash(dequote(Path.area))
  86.             if debug then call writeln(STDOUT,'Updating area' Name.area)
  87.             call listandsort(areadir,areadir||filesbbs,LFMT_BBS)
  88.             call addareatext(areadir,areadir||filesbbs,areatext,areadir||filesbbs,'prepend')
  89.  
  90.             call writeln(STDOUT,'Appending 'areadir Number.area Name.area' to 'fileslist)
  91.             tbuf=CR||CR
  92.             tbuf=tbuf'╒══════════════════════════╤═════════════════════╤══════════════════════════╕'||CR
  93.             tbuf=tbuf'│ ░░░░░▒▒▒▒▒▓▓▓▓▓█████▓▓▓▓▓│'center("AREA: "Number.Area,21)'│▓▓▓▓▓█████▓▓▓▓▓▒▒▒▒▒░░░░░ │'||CR
  94.             tbuf=tbuf'├────────────────┬─────────┴─────────────────────┴─────────┬────────────────┤'||CR
  95.             tbuf=tbuf'│ ░░░░░▒▒▒▒▒▓▓▓▓▓│'center(Name.Area,41)'│▓▓▓▓▓▒▒▒▒▒░░░░░ │'||CR
  96.             tbuf=tbuf'╘════════════════╧═════════════════════════════════════════╧════════════════╛'||CR
  97.  
  98.             if debug then call writeln(STDOUT,'Adding Area Banner to 'fileslist)
  99.             if ~open('tbl', fileslist, 'A') then do
  100.                 call writeln(STDOUT,'Cannot append Area Header to 'fileslist)
  101.                 signal cleanup
  102.             end
  103.             call writech('tbl',tbuf)
  104.             close('tbl')
  105.             drop tbuf
  106.             if exists(areadir||areatext) then do
  107.                 if debug then call writeln(STDOUT,'Adding Area description to 'fileslist)
  108.                 com='Type >> "'fileslist'" "'areadir||areatext'"'
  109.                 address COMMAND com
  110.             end
  111.  
  112.             call listandsort(areadir,tmpbbs,LFMT_LIST)
  113.  
  114.             if ~open('ifn',tmpbbs,'R') then do
  115.                 call writeln(STDOUT,'wraptofile:Cannot open 'tmpbbs)
  116.                 signal cleanup
  117.             end
  118.             if ~open('ofn',fileslist,'A') then do
  119.                 call writeln(STDOUT,'wraptofile:Cannot append Area List to 'fileslist)
  120.                 signal cleanup
  121.             end
  122.             do while ~eof('ifn')
  123.                 line=readln('ifn')
  124.                 if left(line,1) ~= " " then call writech('ofn',' 'wrap_line(line,FLLEN,MARGINALL)) 
  125.                 else call writech('ofn',line||cr)
  126.             end /*eof */
  127.             call close('ifn')
  128.             call close('ofn')
  129.         end
  130.     end
  131. address COMMAND 'Copy' fileslist allfileslist
  132. address COMMAND 'FileNote "'allfileslist'" "'listnote'"'
  133. call writeln(STDOUT,'Archiving 'allfileslist' as 'allfilesarc)
  134. address COMMAND 'lha -2 u "'allfilesarc'" "'allfileslist'"'
  135. address COMMAND 'FileNote "'allfilesarc'" "'listnote'"'
  136. call writeln(STDOUT,' File Listing completed')
  137. cleanup:
  138. call delete(fileslist)
  139. call delete(tmpbbs)
  140. exit 0
  141.    
  142. listandsort:
  143. /* list <tdir> with <lfmt> and sort to <tfile> */
  144. tdir=arg(1);tfile=arg(2);lfmt=arg(3)
  145. las='PIPE LIST 'tdir||exclude' FILES NOHEAD LFORMAT 'lfmt' | SORT In: 'tfile
  146. address command las
  147. return 0
  148.  
  149. /* prepend area.text to files.bbs                               */
  150. /*    addareatext(areadir,files.bbs,area.text,output)           */
  151. /*    addareatext(areadir,files.bbs,area.text,output,where)     */
  152. /* where= append or prepend(DEFAULT)                            */
  153. /*  example:                                                    */
  154. /*    call addareatext(Path.area,availlist,areatext,availlist)  */
  155. addareatext:
  156. descfile=addslash(dequote(arg(1)))||arg(3)
  157. inlist=arg(2);tolist=arg(4);where=arg(5)
  158. if ~exists(inlist) then do
  159.     call writeln(STDOUT,'addareatext: cannot find 'inlist)
  160.     return 20
  161. end
  162.  
  163. if ~exists(descfile) then do
  164.     call writeln(STDOUT,'addareatext: cannot find 'descfile' using 'default)
  165.     if where='append' then do
  166.         call open('ds',descfile,'A')
  167.         call writech('ds',default)
  168.     end;else do
  169.         call open('ds',descfile,'W')
  170.         call writech('ds',default)
  171.     end
  172.     call close('ds')  
  173. end
  174. if where='append' then call join(inlist,descfile,tolist)
  175.     else call join(descfile,inlist,tolist)
  176. return 0
  177.  
  178. wrap_line:
  179. text=arg(1)
  180. right_edge=arg(2)  /* line length */
  181. left_edge=arg(3)  /*   margin    */
  182. new_text=''
  183. do while length(text) > 0
  184.     broken_word=0
  185.     if length(text) < right_edge then do
  186.         new_text=new_text || text || '0a'x
  187.         text=''
  188.     end;else do
  189.         temp_text=strip(text,l)
  190.         diff=length(text) - length(temp_text)
  191.         first_break=lastpos(' ',temp_text,right_edge - diff)
  192.         break_point=first_break + diff
  193.         if left_edge=break_point then do
  194.             break_point=right_edge - 1
  195.             broken_word=1
  196.         end
  197.         new_text=new_text || strip(left(text,break_point),t)
  198.         if broken_word then do
  199.             new_text=new_text || '-'
  200.         end
  201.         new_text=new_text || '0a'x
  202.         text=copies(' ',left_edge) || strip(right(text,length(text) - break_point),l)
  203.     end
  204. end
  205. return new_text
  206.  
  207. /*
  208.     join -- a 'front end' for join. Fixes a problem with join.
  209.     uses a tempfile if target filename is same as one to cat
  210. */
  211. join:
  212. x=arg(1)' 'arg(2)' 'arg(3)
  213. temp='arexxtempfile'
  214. do i=1 to (words(x)-1)
  215.     if word(x,i)=word(x,words(x)) then do
  216.         oops=word(x,words(x))
  217.         x=delword(x,words(x))||'TO '||temp
  218.         address COMMAND 'Join' x
  219.         address COMMAND 'Copy 'temp' 'oops
  220.         call delete(temp)
  221.         return 0
  222.     end
  223. end
  224. x=arg(1)' 'arg(2)' TO 'arg(3)
  225. address COMMAND 'Join' x
  226. return 0
  227.  
  228. addslash:
  229. curr=arg(1)
  230. select
  231.     when right(curr, 1)=":" then nop
  232.         when right(curr, 1)="/" then nop
  233.             otherwise curr=curr"/"
  234. end
  235. return curr
  236.  
  237. /* a useful procedure by Walt Sullivan  */
  238. dequote:
  239. parse arg thing
  240. parse var thing '"' unq_thing '"'
  241. if unq_thing ~= "" then return unq_thing
  242. return thing
  243.  
  244. halt:
  245. ioerr:
  246. break_c:
  247. break_d:
  248. call writech(stdout,cr)
  249. call cleanup()
  250. exit 10
  251.  
  252.